package com.sba.core.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

import com.sba.core.repository.BaseRepository;
import com.sba.core.service.BaseService;

/**
 * 基本service的实现, 其他service继承此service.
 * 
 * @author feiliming
 *
 */
public class BaseServiceImpl<T> implements BaseService<T> {

	@Autowired
	private BaseRepository<T> baseRepository;

	@Override
	public T saveOrUpdate(T entity) {
		return baseRepository.save(entity);
	}

	@Override
	public T findById(Long id) {
		return baseRepository.findOne(id);
	}

	@Override
	public boolean exists(Long id) {
		return baseRepository.exists(id);
	}

	@Override
	public void delete(Long id) {
		baseRepository.delete(id);
	}

	@Override
	public void delete(T entity) {
		baseRepository.delete(entity);
	}
	
	@Override
	public void delete(Iterable<? extends T> entities) {
		baseRepository.delete(entities);
	}

	@Override
	public List<T> findAll() {
		return baseRepository.findAll();
	}

	@Override
	public List<T> findAll(Sort sort) {
		return baseRepository.findAll(sort);
	}

	@Override
	public List<T> findAll(Iterable<Long> ids) {
		return baseRepository.findAll(ids);
	}

	@Override
	public Page<T> findAll(Pageable pageable) {
		return baseRepository.findAll(pageable);
	}

}
